package com.kzc.service.impl;

import com.kzc.util.MobClient;


/**
 * Created by anyleKe on 2016/1/30.
 */
public class MobServiceImpl {

    private String appkey;
    private String phone ;
    private String zone ;
    private String code ;

    /**
     *
     * appkey 应用KEY
     * @param phone 电话号码 xxxxxxxxx
     * zone 区号 86
     * @param code 验证码 xx
     */
    public MobServiceImpl(String phone, String code) {
        super();
        this.appkey = "f48ffdbfcb66";
        this.phone = phone;
        this.zone = "86";
        this.code = code;
    }

    /**
     * 服务端发起验证请求验证移动端(手机)发送的短信
     * @return
     * @throws Exception
     */
    public  String go() throws Exception{

        String address = "https://webapi.sms.mob.com/sms/verify";
        MobClient client = null;
        System.out.println("appkey: "+appkey + " phone: "+phone + " zone: "+zone +" code: "+code );
        try {
            client = new MobClient(address);
            client.addParam("appkey", appkey).addParam("phone", phone)
                    .addParam("zone", zone).addParam("code", code);
            client.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
            client.addRequestProperty("Accept", "application/json");
            String result = client.post();
            return result;
        } finally {
            client.release();
        }
    }

    public static void main(String[] args) throws Exception {

//        new SmsVerifyKit("xx", "xx", "xx", "xx").go();

    }
}
